package logic

import (
	"context"
	"errors"
	"go.uber.org/zap"
	"order_srv/internal/dao"
	"order_srv/internal/svc"
	"order_srv/order"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type InvoiceCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInvoiceCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InvoiceCreateLogic {
	return &InvoiceCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加发票
func (l *InvoiceCreateLogic) InvoiceCreate(in *order.InvoiceCreateRequest) (*order.InvoiceCreateResponse, error) {
	//调用逻辑
	invoice, err := dao.InvoiceCreate(in)
	if err != nil {
		pkg.Error("发票添加失败", zap.Error(err))
		return nil, errors.New("发票添加失败")
	}
	pkg.Info("发票添加成功", zap.Int64("invoiceId", int64(invoice.Id)))
	return &order.InvoiceCreateResponse{
		InvoiceId: int64(invoice.Id),
	}, nil
}
